<template>
  <div class="mod-config">

    <split-pane class="splitPane" :min-percent='10' :default-percent='10' split="vertical">
      <template slot="paneL">
        <div class="treeViewContainer">
          <tree-view ref="treeView" :treeData="deepCategoryTreeList" :checkChangedHandler="getDataList"></tree-view>
        </div>
      </template>
      <template slot="paneR">
        <table-view ref="view"
                    :searchAttrs="searchAttrs"
                    :primaryKey="primaryKey"
                    :listApiName="listApiName"
                    :deleteApiName="deleteApiName"
                    :saveAuthName="saveAuthName"
                    :deleteAuthName="deleteAuthName"
                    :showAttrs="showAttrs"
                    :exportPlantFunc="exportPlantFunc"
        >
        </table-view>
      </template>
    </split-pane>

    <deep-product-info-add-or-update v-if="productInfoVisible" ref="deepProductInfo"></deep-product-info-add-or-update>
    <client-info-add-or-update v-if="clientInfoVisible" ref="clientInfo"></client-info-add-or-update>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <deep-category-add-or-update v-if="deepCategoryInfoVisible" ref="deepCategory" ></deep-category-add-or-update>
  </div>
</template>

<script>
  import tableView from '@/components/tableView'
  import treeView from '@/components/treeView'
  import basicMixins from '@/utils/commonViewMixins'
  import deepProductInfoAddOrUpdate from '@/views/modules/deep/deepproductinfo-add-or-update'
  import ClientInfoAddOrUpdate from '@/views/modules/client/clientinfo-add-or-update'
  import DeepCategoryAddOrUpdate from '@/views/modules/deep/deepcategory-add-or-update'
  import AddOrUpdate from './deeporderdetail-add-or-update'
  import {exportHandle} from '@/utils'
  import {mRequest} from '@/utils/request'
  export default {
    mixins: [basicMixins],
    data () {
      return {
        searchAttrs: {
          productNo: {
            placeholder: '请输入产品名称',
          },
          clientId: {
            label: '客户名称',
            clearable: true,
            type: 'autoComplete',
            placeholder: '请输入客户名称',
            querySearchApiName: 'clientApi/getClientList'
          },
          deepCategoryId: {
            type: 'func',
            dataFunc: () => {
              return this.$refs.treeView.$refs.treeForm.getCheckedKeys()[0]
            }
          },
          dateTimeRange: {
            type: 'date',
            dateType: 'daterange',
            clearable: true
          }
        },
        deepCategoryTreeList: [],
        defaultProps: {
          children: 'children',
          label: 'name'
        },
        productInfoVisible: false,
        clientInfoVisible: false,
        deepCategoryInfoVisible: false,
        primaryKey: 'id',
        listApiName: 'deepApi/listDeepOrderDetailList',
        deleteApiName: 'deepApi/deleteDeepOrderDetail',
        saveAuthName: 'deep:deeporderdetail:save',
        deleteAuthName: 'deep:deeporderdetail:delete',
        showAttrs:{
          deepOrderNo:{
            label: '订单编号',
            width: 200,
            type: 'labelWithStatus',
            statusAttr: 'messageStatus',
            items: [
              {value: 0, text: '未读', tagType: 'danger'}
            ]
          },
          productNo:{
            label: '产品名称',
            width:150
          },
          deepProductImage: {label: '深加工样图', type: 'image'},
          deepCategoryName:{
            label: '深加工方式',
            width:100
          },
          // orderSource:{
          //   label: '订单来源',
          //   type: 'radio',
          //   items: [
          //     {value: 1, text: '来料加工', tagType: 'warning'}
          //   ]
          // },
          productPrice: {
            label: '单价',
            showAuthName: 'order:unitprice:show'
          },
          clientName:{
            label: '客户名称',
            width:120
          },
          deliveryTime:{
            label: '交货时间',
            type: 'date',
            width:120
          },
          orderProductNumber:{
            label: '订单数量'
          },
          deepSemiFinishedCount:{
            label: '半成品'
          },

          deepFinishAddCount: {
            label: '成品数量'
          },
          boxSupplyWay: {
            label: '包装方式',
            type: 'radio',
            items: [
              {text: '自制纸箱', value: 0,tagType: 'success'},
              {text: '托盘', value: 1,tagType: 'info'},
              {text: '客供纸箱', value: 2},
              {text: '套袋', value: 3,tagType: 'danger'},
              {text: '不套袋', value: 4,tagType: 'warning'}
            ]
          },
          remark: {label: '备注', width: 140},
          status: {
            label: '状态',
            type: 'radio',
            items: [
              {value: 0, text: '光瓶待生产',tagType: 'info'},
              {value: 1, text: '暂时下线', tagType: 'warning'},
              {value: 2, text: '加急', tagType: 'warning'},
              {value: 3, text: '正常', tagType: 'primary'},
              {value: 4, text: '生产中', tagType: 'success'},
              {value: 5, text: '生产完成', tagType: 'success'},
              {value: 10, text: '出库中', tagType: 'warning'},
              {value: 11, text: '出库完成', tagType: 'success'},
              {value: 99, text: '取消', tagType: 'danger'}
            ]
          }
        }
      }
    },
    mounted() {
      this.initDeepCategoryTreeListInit('deepTypeList')
    },
    methods: {
      initDeepCategoryTreeListInit(attrName = 'deepTypeList') {
        mRequest('deepApi/deepCategoryList', {}, (res) => {
          const deepCategoryList = this.R.pathOr([], ['data', 'list'], res)
          const deepCategoryTreeList = [{
            id: '',
            name: '深加工工艺',
            nodeType: 0,
            children: []
          }]
          deepCategoryTreeList[0].children = deepCategoryList
          this.deepCategoryTreeList = deepCategoryTreeList;
        })
      },
      openDeepProductInfoDialog(cb) {
        this.productInfoVisible = true
        this.$nextTick(() => {
          if (!this.R.isNil(this.$refs.deepProductInfo)) {
            this.$refs.deepProductInfo.init(null, {status: 1}, cb)
          }
        })
      },
      openClientInfoDialog(cb) {
        this.clientInfoVisible = true
        this.$nextTick(() => {
          if (!this.R.isNil(this.$refs.clientInfo)) {
            this.$refs.clientInfo.init(null, {status: 1}, cb)
          }
        })
      },
      openDeepCategoryInfoDialog(cb){
        this.deepCategoryInfoVisible = true
        this.$nextTick(() => {
          if (!this.R.isNil(this.$refs.deepCategory)) {
            this.$refs.deepCategory.init(null, {status: 1}, cb)
          }
        })
      },
      openProductPlanNotice(id) {
        exportHandle('orderApi/getDeepOrderDetailExport', {orderId: id})
      },
      exportPlantFunc(id) {
        console.log(id)
      }
    },
    components: {
      deepProductInfoAddOrUpdate,
      ClientInfoAddOrUpdate,
      DeepCategoryAddOrUpdate,
      AddOrUpdate,
      treeView,
      tableView
    }
  }
</script>
